
import React from 'react';


class CartItem extends React.Component {
    render(){
        // 获得由父组件通过 attribute 传递的数据
        // let ordinal = this.props.ordinal;
        // let item = this.props.item ;
        // let remove = this.props.remove ;

        let { ordinal, item, decrease, increase, remove } = this.props ;

        return (
            <div className="item">
                <div className="ordinal">{ ordinal }</div>
                <div className="name">{ item.name }</div>
                <div className="price">{ item.price }</div>
                <div className="amount">
                    <i onClick={ () => decrease(item.id) }>-</i>
                    <b>{ item.amount }</b>
                    <i onClick={ () => increase(item.id) }>+</i>
                </div>
                <div className="subtotal">{ item.price * item.amount }</div>
                <div className="operation">
                    <i onClick={ () => remove(item.id) }>删除</i>
                </div>
            </div>
        )
    }
}

export default CartItem ;